import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.anon.service.impl.UserService2;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author 徒有琴
 */
@RunWith(SpringJUnit4ClassRunner.class) //由SpringJUnit4ClassRunner启动测试
@ContextConfiguration("classpath:spring-anon.xml") //spring的配置文件位置
public class SpringTest {
    @Autowired
    UserService2 userService2;

    @Test
    public void test(){
        userService2.sayHello();
    }

//    public static void main(String[] args) {
//        ClassPathXmlApplicationContext context =
//                new ClassPathXmlApplicationContext("spring-anon.xml");
//        UserService2 userService2=context.getBean(UserService2.class);
//        userService2.sayHello();
//        FoodTypeService com.service=context.getBean(FoodTypeService.class);
//        System.out.println(com.service);
//        try {
//          //  com.service.add();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        //根据类型获取bean,这个类型的bean需要是唯一的
//        UserService userService=context.getBean(UserService.class);
//        userService.sayHello();
//        User user = (User) context.getBean("user3");
//        System.out.println(user);
//        System.out.println(user.getAddress().getPosition());

//        Address address1=context.getBean(Address.class);
//        System.out.println(address1);
//        Address address2=context.getBean(Address.class);
//        System.out.println(address2);
//        context.close();
//    }
}
